<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" style="display: none;">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['buss:sqzxt:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['buss:sqzxt:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['buss:sqzxt:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-form ref="elForm"    size="small" :disabled="true" label-width="120px">
      <el-row type="flex" justify="start" align="top"  >
        <el-form-item label="社区数量" prop="sssqs">
          <el-input v-model="dataWgWgsqSq.sssqs"  placeholder="" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="总户数" prop="hs">
          <el-input   v-model="dataWgWgsqSq.hs" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="存款户数" prop="ckhs">
          <el-input   v-model="dataWgWgsqSq.ckhs" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="存款金额" prop="ckye">
          <el-input   v-model="dataWgWgsqSq.ckye" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="贷款户数" prop="field126">
          <el-input   v-model="dataWgWgsqSq.dkhs" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="贷款余额" prop="field126">
          <el-input   v-model="dataWgWgsqSq.dkye" :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-row>
      <el-row type="flex" justify="start" align="top"  >
        <el-form-item label="电银产品数" prop="field124">
          <el-input   v-model="dataWgWgsqSq.dzyhgs" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="家庭产品覆盖面" prop="field123">
          <el-input   v-model="dataWgWgsqSq.productCoverage" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="有效家庭覆盖面" prop="field125">
          <el-input   v-model="dataWgWgsqSq.vaildCoverage" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
        <el-form-item label="授信金额" prop="field126">
          <el-input   v-model="dataWgWgsqSq.sxje" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="授信签约率" prop="field126">
          <el-input   v-model="dataWgWgsqSq.sxqyl" :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-row>
    </el-form>

    <el-table v-loading="loading" :data="sqzxtList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="所属社区" align="center" prop="sssq"   :show-overflow-tooltip="true" >
        <template slot-scope="scope">
          <!-- <el-button
            size="small"
            type="text"
            @click="SQJump(scope.row.sssq)"
            v-hasPermi="['buss:customer:query']"
          >{{ scope.row.sssq }}</el-button> -->
          <router-link :to="{path:'/sq/sqcu/',query: {sqZ: scope.row.sssq}}" class="link-type">
            <span>{{ scope.row.sssq }}</span>
          </router-link>
        </template>
      </el-table-column>
	  <el-table-column label="数据日期" width="120"align="center" prop="sjrq"           />
      <el-table-column label="存款户数" align="center" prop="ckhs"  />
      <el-table-column label="存款金额" width="120" align="center" prop="ckye"   />
      <el-table-column label="贷款户数" align="center" prop="dkhs"   />
      <el-table-column label="贷款余额" width="120" align="center" prop="dkye"   />
      <el-table-column label="etc户数" align="center" prop="etchs"    />
      <el-table-column label="信用卡户数" align="center" prop="xykhs"  />
      <el-table-column label="省级微信户数" align="center" prop="sjwxhs"   />
      <el-table-column label="社保卡户数" align="center" prop="sbkhs"   />
      <el-table-column label="有效贷款人数" align="center" prop="yxdkrs"   />
      <el-table-column label="人数" align="center" prop="rs"   />
      <el-table-column label="电子银行个数" align="center" prop="dzyhgs"   />
      <el-table-column label="家庭有产品户数" align="center" prop="productFamilyHs"   />
      <el-table-column label="产品覆盖面" width="120" align="center" prop="productCoverage"      />
      <el-table-column label="有效家庭户数" align="center" prop="vaildFamilyHs"   />
      <el-table-column label="有效家庭覆盖面" width="120" align="center" prop="familyCoverage"  />
      <el-table-column label="管户机构" width="120" align="center" prop="orgId" :formatter="orgIdFormat" />
      <el-table-column label="管户经理" align="center" prop="userId" :formatter="userIdFormat" />
<!--      <el-table-column label="全部入住率" align="center" prop="rzlcoount"        />
      <el-table-column label="家庭信息覆盖面" align="center" prop="familyfgm"    />
      <el-table-column label="小区入住率" align="center" prop="rzl"            />
      <el-table-column label="乡镇居民占比" align="center" prop="xzjmzb"       />
      <el-table-column label="个体工商户占比" align="center" prop="gtgshzb"    />
      <el-table-column label="公职人员占比" align="center" prop="gzryzb"         />
      <el-table-column label="预授信金额" align="center" prop="amountYsh"      />
      <el-table-column label="预授信人数" align="center" prop="ifysx"          /> -->
      <el-table-column label="签约人数" align="center" prop="qyZjhm"            />
      <el-table-column label="授信金额" width="120" align="center" prop="sxje"              />
      <el-table-column label="授信签约率" width="120" align="center" prop="familyQyCoverage"   />
      <el-table-column label="小区有效授信数" align="center" prop="sfyxdkAll"  />

      <!-- <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['buss:sqzxt:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['buss:sqzxt:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改网格社区按社区维度统计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSqzxt, getSqzxt, delSqzxt, addSqzxt, updateSqzxt } from "@/api/buss/sqzxt";

export default {
  name: "Sqzxt",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      orgIdOptions: [],
      userIdOptions: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 网格社区按社区维度统计表格数据
      sqzxtList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        sssq: null,
        hs: null,
        ckhs: null,
        ckye: null,
        dkhs: null,
        dkye: null,
        etchs: null,
        xykhs: null,
        sjwxhs: null,
        sbkhs: null,
        yxdkrs: null,
        rs: null,
        dzyhgs: null,
        productFamilyHs: null,
        productCoverage: null,
        vaildFamilyHs: null,
        familyCoverage: null,
        orgId: null,
        managerId: null,
        rzlcoount: null,
        familyfgm: null,
        rzl: null,
        xzjmzb: null,
        gtgshzb: null,
        gzryzb: null,
        sjrq: null,
        amountYsh: null,
        ifysx: null,
        qyZjhm: null,
        sxje: null,
        familyQyCoverage: null,
        sfyxdkAll: null
      },
      dataWgWgsqSq: {
        // sssqs: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_org_id").then(response => {
      this.orgIdOptions = response.data;
    });
    this.getDicts("sys_user_id").then(response => {
      this.userIdOptions = response.data;
    });
  },
  methods: {
    /** 查询网格社区按社区维度统计列表 */
    getList() {
      this.loading = true;
      listSqzxt(this.queryParams).then(response => {
        this.sqzxtList = response.data.doList.rows;
        this.dataWgWgsqSq = response.data.dataWgWgsqSq;
        this.total = response.data.doList.total;
        this.loading = false;
      });
    },
    //社区跳转
    SQJump(sssq) {
      //const tableId = row.idCard;
      //this.$router.push({ path: '/sqzxt/sqcustomerindex', query: { sssq } });
      this.$router.push({ name: 'sqcustomerindex',params:{sssq:sssq}});
      console.log(sssq)
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sssq: null,
        hs: null,
        ckhs: null,
        ckye: null,
        dkhs: null,
        dkye: null,
        etchs: null,
        xykhs: null,
        sjwxhs: null,
        sbkhs: null,
        yxdkrs: null,
        rs: null,
        dzyhgs: null,
        productFamilyHs: null,
        productCoverage: null,
        vaildFamilyHs: null,
        familyCoverage: null,
        orgId: null,
        managerId: null,
        rzlcoount: null,
        familyfgm: null,
        rzl: null,
        xzjmzb: null,
        gtgshzb: null,
        gzryzb: null,
        sjrq: null,
        amountYsh: null,
        ifysx: null,
        qyZjhm: null,
        sxje: null,
        familyQyCoverage: null,
        sfyxdkAll: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({path: '/sqcustomerindex'})
      this.reset();
      this.open = true;
      this.title = "添加网格社区按社区维度统计";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSqzxt(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改网格社区按社区维度统计";
      });
    },
    orgIdFormat(row, column) {
      return this.selectDictLabel(this.orgIdOptions, row.orgId);
    },
    userIdFormat(row, column) {
      return this.selectDictLabel(this.userIdOptions, row.userId);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSqzxt(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSqzxt(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除网格社区按社区维度统计编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSqzxt(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('buss/sqzxt/export', {
        ...this.queryParams
      }, `buss_sqzxt.xlsx`)
    }
  }
};
</script>
